Skip to content

[docs] Fix imports that fail on main in four English docs - #50817

Merged
Rocketknight1 merged 1 commit into
huggingface:mainfrom
burrows99:docs-fix-broken-imports
Nov 16, 2026
Merged

Rocketknight1 merged 1 commit into
huggingface:mainfrom
burrows99:docs-fix-broken-imports

Conversation

@burrows99

@burrows99 burrows99 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🤗 Transformers CI

What does this PR do?

Four code examples in the English docs fail on their import line on current main. This PR fixes all four in one go.

This is the single bulk PR proposed in #50793, following the suggestion on #50607. That issue has the sweep script and its full output. It checked all 1,750 from transformers... import ... statements in docs/source/en (3,050 names). Apart from 12 deliberate placeholders (MyModel, MyVLM*, BrandNewLlama*), five names do not exist: these four, plus infer_device in tasks/any_to_any.md, which is already fixed in #50792.

File Broken line on main Fix
model_doc/tapas.md from transformers import AdamW, ... (removed from transformers) from torch.optim import AdamW
model_doc/trocr.md BitsandBytesConfig (typo, ImportError) BitsAndBytesConfig
model_doc/persimmon.md from transformers import ..., PersimmonTokenizer (no such class) AutoTokenizer. The checkpoint's tokenizer_config.json declares LlamaTokenizer, which the note under the example also mentions
testing.md from transformers.testing_utils import MemoryCleanupMixin, ... from ...test_memory_cleanup_mixin import MemoryCleanupMixin, the import the test files use. The mixin lives in tests/test_memory_cleanup_mixin.py, as the next section of the page already says. I also added import unittest, since the snippet subclasses unittest.TestCase

Only the English pages are changed, since the other languages are machine-translated (#50120). There are no code changes.

flowchart TD
    A[Sweep every transformers import in docs/source/en] --> B[5 names that do not exist]
    B --> C[any_to_any infer_device: fixed in 50792]
    B --> D[tapas, trocr, persimmon, testing: this PR]
    D -->|Before| E[ImportError on the first line of each example]
    D -->|After| F[Each block's imports run, sweep finds only the any_to_any line]
Loading

Narrated recording, main then branch (sound on). I shortened the two-minute wait while the Persimmon tokenizer converts; every command and every line of output is still shown:

evidence_upload.mp4

Reproducer

check_block.py (not part of the PR) takes a file at a git ref, finds the fenced code block that contains a given string, and runs that block's import lines. With full it runs the whole block instead. It runs them as a module under tests/models/, so the relative import that test files use resolves. Run from the repo root with PYTHONPATH=src, CPU only.

On main (cf13eb9):

$ python check_block.py upstream/main docs/source/en/model_doc/tapas.md "optimizer = AdamW"
=> ImportError: cannot import name 'AdamW' from 'transformers'
$ python check_block.py upstream/main docs/source/en/model_doc/trocr.md "quantization_config ="
=> ImportError: cannot import name 'BitsandBytesConfig' from 'transformers'
$ python check_block.py upstream/main docs/source/en/model_doc/persimmon.md PersimmonForCausalLM
=> ImportError: cannot import name 'PersimmonTokenizer' from 'transformers'
$ python check_block.py upstream/main docs/source/en/testing.md MyModelIntegrationTest
=> ImportError: cannot import name 'MemoryCleanupMixin' from 'transformers.testing_utils'

On this branch, the same three model-doc blocks print => OK. The testing.md block, run whole with full, defines MyModelIntegrationTest(MemoryCleanupMixin, unittest.TestCase) and prints => OK.

For Persimmon, AutoTokenizer loads the real checkpoint's tokenizer:

$ python -c "... AutoTokenizer.from_pretrained('adept/persimmon-8b-base') ..."
tokenizer_class in checkpoint: LlamaTokenizer
AutoTokenizer -> TokenizersBackend [71013, 76624, 71385, 71374, 73498]

The sweep, on a git archive of main and then on this branch, with the placeholders filtered out:

main:   model_doc/persimmon.md:70 PersimmonTokenizer
        model_doc/tapas.md:223    AdamW
        model_doc/trocr.md:70     BitsandBytesConfig
        tasks/any_to_any.md:34    infer_device
        testing.md:375            MemoryCleanupMixin
branch: tasks/any_to_any.md:34    infer_device

Checks

  • python utils/checkers.py ruff_check,ruff_format,init_isort,sort_auto_mappings,noisy_comments,doc_toc,doctest_list --no-cache: all 7 passed. git diff --check is clean.
  • add_dates not run usefully: my clone is shallow, so it reads every model card's first commit as the clone date and flags any card it touches. The dates lines are unchanged in this PR.
  • The full examples (TAPAS fine-tuning, TrOCR 8-bit, Persimmon 8B) were not run, only their imports. No GPU here.
  • Docs build not run locally.

AI assistance (Claude Code) was used to find the broken imports, make the change, run the checks above and record the video.

Who can review?

Documentation: @stevhliu

Fixes #50793

- tapas.md: AdamW was removed from transformers; import it from torch.optim
- trocr.md: BitsandBytesConfig -> BitsAndBytesConfig
- persimmon.md: there is no PersimmonTokenizer; load it with AutoTokenizer
- testing.md: MemoryCleanupMixin lives in tests/test_memory_cleanup_mixin.py,
  not transformers.testing_utils; also import unittest, which the snippet uses

@Rocketknight1 Rocketknight1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, LGTM!

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Pages changed in this PR:

@Rocketknight1
Rocketknight1 added this pull request to the merge queue Nov 16, 2026
Merged via the queue into huggingface:main with commit 43bfd16 Nov 16, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[docs] Five imports in the English docs fail on main (single sweep)

3 participants